﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using RuleCode.Common;

namespace map.taobao
{
    public partial class pointShop : System.Web.UI.Page
    {
        #region 页面载入
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (validateRequest())
                {
                    this.AreaHyperLink.Text = Request["area"];
                    this.AreaHyperLink.NavigateUrl = ("~/search/areadetail.aspx?id=" + Request.QueryString["id"]);
                    BindWebPager();
                }
            }
        }
        #endregion

        #region 辅助方法
        private void BindWebPager()
        {
            if (validateRequest())
            {
                string sqlText = "exec [searchpointshop] @clat=" + Request["lat"] + ", @clong="+Request["lng"];
                sqlText += ", @keywordtext='" + Request["searchKeys"] + "'";
                string searchKeys = "";
                if (Request["searchKeys"] != null)
                {
                    searchKeys = Request["searchKeys"].ToString();
                }
                sqlText += ", @keyword='" + zfunction.ReplaceKeyWord(searchKeys) + "'";
                sqlText += ", @rsms=" + Request["rsmsValue"];
                sqlText += ", @qtth=" + Request["qtthValue"];
                sqlText += ", @stwx=" + Request["shwxValue"];
                sqlText += ", @sdfh=" + Request["sdfhValue"];
                sqlText += ", @cataid='" + Request["currentCate"] + "'";
                DataSet dSet = SqlHelper.Instance.ExecuteQuery(sqlText);
                if (dSet.Tables.Count > 0 )
                {
                    int count = dSet.Tables[0].Rows.Count;
                    this.TotalCountLabel.Text = count.ToString() + " 家店铺符合要求";
                    this.MainWebPager.DataSource = dSet.Tables[0];
                    this.MainWebPager.DataBind();
                
                }
            }
        }

        private bool validateRequest()
        {
            return Request["lat"] != null && Request["lng"] != null && Request["area"] != null;
        }
        #endregion

        #region 事件
        protected void MainWebPager_PageIndexChanged(object sender, RuleCode.Controls.PageChangedEventArgs e)
        {
            this.MainWebPager.CurrentPageIndex = e.NewPageIndex;
            BindWebPager();
        }
        #endregion
    }
}
